import canvasAbstract from './canvasAbstract';
import config from '../config';
import position from '../service/position';
import model from '../model/tank'
export default new (class tank extends canvasAbstract implements ICanvas{
    intervalId:number = 0
    num(): number {
        return config.tank.num;
    }
    model(): IModelAbstract {
        return model
    }
    render(): void {
        this.createModels()
        super.renderModels()
        this.intervalId = setInterval(() => this.renderModels(),config.timeout)
    }
    public renderModels(){
        this.ctx.clearRect(0,0,config.canvas.width,config.canvas.height);
        super.renderModels()
    }
    protected createModels(){
        for(let i = 0; i < this.num(); i++){
            const pos = position.position();
            const model = this.model();
            const instance = new model(pos.x,0);
            this.models.push(instance);
        }
    }

    stop(): void {
        clearInterval(this.intervalId);
    }
})('tank');